﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL;

public partial class UserWork_Plan_user_PlanManage : System.Web.UI.Page
{
    B_UserPlan bll = new B_UserPlan();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        string strLogin = Session["LoginName"].ToString();
        if (!IsPostBack)
        {
            this.SelectTodayPlan(strLogin);
            this.txtBegin.Text = DateTime.Now.Date.ToShortDateString();
            DateTime dt = DateTime.Parse(txtBegin.Text.Trim());
            IList<string> ilst = bll.GetRemark(strLogin, dt);
            if (ilst.Count > 0)
            {
                txtUser.Text = ilst[1].ToString();
                txtManager.Text = ilst[0].ToString();
            }
        }
    }
    private void SelectTodayPlan(string strLogin)
    {
        IList<M_userPlan> lst = bll.GetList(strLogin);
        if (lst != null && lst.Count() > 0)
        {
            rpPlan.DataSource = lst;
            rpPlan.DataBind();
        }
    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        txtUser.Text = "";
        txtManager.Text = "";
        string strLogin = Session["LoginName"].ToString();
        
        if ((txtBegin.Text.Trim() != ""))
        {
            DateTime dt = DateTime.Parse(txtBegin.Text.Trim());
            IList<M_userPlan> lst = bll.GetList(strLogin, dt);
            rpPlan.DataSource = lst;
            rpPlan.DataBind();
            IList<string> ilst = bll.GetRemark(strLogin, dt);
            if (ilst.Count > 0)
            {
                txtUser.Text = ilst[1].ToString();
                txtManager.Text = ilst[0].ToString();
            }
        }
    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        string strLogin = Session["LoginName"].ToString();
        if (this.txtBegin.Text.Trim() != "")
        {
            string strManagerRemark = this.txtManager.Text.Trim();
            string strUserRemark = this.txtUser.Text.Trim();
            string strUser = strLogin;
            DateTime dt = DateTime.Parse(this.txtBegin.Text.Trim());
            if (bll.UpdateUserPlanM(strManagerRemark, strUserRemark, strUser, dt) == 1)
            {
                Response.Write("提交成功");
            }
            else
            {
                Response.Write("提交失败");
            }
        }
    }
}